<template>
	<view class="headPortrait">
		<view class="personalData-item" @click="clk()">
			头像
		</view>
		<avatar
			:bgImage="imgBg"
			selWidth="150px" selHeight="150px"  ref='avatar' fileType='png' :avatarSrc="url" @upload="myUpload"  quality="1" inner=true
			avatarStyle="width: 300rpx; height: 300rpx; margin: auto;background:rgba(0,0,0,.2)"
			class="personalData-item-image"
			>
		</avatar>
	</view>
</template>

<script>
	import avatar from "@/components/yq-avatar/yq-avatar.vue";
	export default{
		data(){
			return{
				url:"",  // 本地图片/显示
				imgBg: "/static/mescroll/xiaojiejie.jpg",   // 裁剪背景图
				reacdimg:"",// 记录图片网络地址
			}
		},
		components:{
			avatar
		},
		methods:{
			clk() {
				let avatar = this.$refs.avatar;
				avatar.fChooseImg(1, {selWidth: "150px", selHeight: "150px", expWidth: "150px", expHeight: "150px", inner:true}, {data: 'xxx'});
			},
			// 上传文件
			myUpload(rsp) {
				//rsp.avatar.imgSrc = rsp.path;
				// let imageList = Array(rsp.path)
				// let uploadFiles = []
				// imageList.forEach((item, index) => {
				// 	uploadFiles.push({
				// 		imageFile:item
				// 	});
				// })
				let uploadFiles = {
					imageFile:rsp.path
				}
				this.url = uploadFiles.imageFile 
				console.log(uploadFiles)
				const apiUrl = this.$http.apiUrl
				console.log(apiUrl)
				uni.uploadFile({
					header: this.$http.token,
					url: `${apiUrl}app/general/uploadImage.do`,
					filePath: rsp.path,
					name: 'imageFile',
					formData: {
						'imageFile': rsp.path
					},
					success: (uploadFileRes) => {
						let fileData = JSON.parse(uploadFileRes.data)
						// this.uploadHead(fileData.url)
						this.reacdimg = fileData.url // 记录上传图片
						
					},
					complete(res) {
					}
				});
				
			},
		}
		
	}
</script>

<style>
	.personalData-item{
		text-align: center;
	}
	.personalData-item-image{
		margin: auto;
		width: 300rpx;
		height: 300rpx;
	}
</style>
